﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Streambolics.Gui
{
    /// <summary>
    ///     A User Control encapsulating a ListView.
    /// </summary>

    public partial class ListViewUserControl : Streambolics.Gui.StandardUserControl
    {
        public ListViewUserControl ()
        {
            InitializeComponent ();
        }

        protected override void OnBeginLoading (EventArgs e)
        {
            list.BeginUpdate ();
            base.OnBeginLoading (e);
        }

        protected override void OnEndLoading (EventArgs e)
        {
            list.EndUpdate ();
            base.OnEndLoading (e);
        }

        [Browsable (true)]
        public event EventHandler SelectionChanged;

        protected virtual void OnSelectionChanged (EventArgs e)
        {
            if (SelectionChanged != null)
            {
                SelectionChanged.Invoke (this, e);
            }
        }

        protected void DoSelectionChanged ()
        {
            OnSelectionChanged (EventArgs.Empty);
        }

        private void list_SelectedIndexChanged (object sender, EventArgs e)
        {
            if (!Loading)
            {
                DoSelectionChanged ();
            }
        }
    }
}
